package com.gjb6.master.account.Login;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.gjb6.master.R;
import com.gjb6.master.account.UrlCenter;
import com.gjb6.master.common.http.MyHttpRequest;
import com.pachong.android.baseuicomponent.activity.BaseActivity;
import com.pachong.android.framework.httprequest.responsecallbacks.DataRequestListener;

import butterknife.Bind;

public class AgreementActivity extends BaseActivity {

    @Bind(R.id.tv_agreement_us)
    TextView mTvAgreementUs;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();
        initToolsBar();
    }

    private void initData() {
        MyHttpRequest request = new MyHttpRequest(this);
        request.get(UrlCenter.GET_AGREEMENT, null, new DataRequestListener<AgreementEntity>(AgreementEntity.class) {
            @Override
            public void onStart(Context context, String url) {
                super.onStart(context, url);
            }
            @Override
            public void onSuccess(AgreementEntity result) {
                super.onSuccess(result);
                if (result != null && !TextUtils.isEmpty(result.getContent())) {
                    mTvAgreementUs.setText(Html.fromHtml(result.getContent()));
                } else {
                    mTvAgreementUs.setText("");

                }
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                super.onFailure(t, errorNo, strMsg);
            }
        });


    }

    private void initToolsBar() {
        setTitle("用户协议");
        getCustomToolbar().addLeftImageButton(R.mipmap.icon_back1, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    public static void start(Activity activity) {
        Intent intent = new Intent(activity, AgreementActivity.class);
        activity.startActivity(intent);
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.activity_agreement, null);
    }
}
